package cn.ouryears.common.datasource;

import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;

public class DynamicDataSourceInterceptor {
    
    public void around(ProceedingJoinPoint point){
        
        String methodName = point.getSignature().getName();
        if(StringUtils.isNotEmpty(methodName)){
            if(methodName.startsWith("save") || methodName.startsWith("update")
                            ||methodName.startsWith("delete")||methodName.startsWith("process")){
                DbContextHolder.setDbType("writeDataSource");
                return ;
            }
        }
        DbContextHolder.setDbType("readDataSource");
        return ;
    }
    
    public void setReadDataSource(){
    	DbContextHolder.setDbType("readDataSource");
    }
    
    public void setWriteDataSource(){
    	DbContextHolder.setDbType("writeDataSource");
    }
}
